<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>使用Clojure开发Web入门系列（一） - (power up)</title>
  <meta name="renderer" content="webkit" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>

<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">


<meta name="author" content="Kevin Jiang" /><meta name="description" content="对于Clojure语言这里有一些很好的入门教程： Learn X in Y minutes Clojure - Functional Programming for the JVM Clojure koans 零、需要了解的知识 Web http Clojure Leiningen HTML Java 一、安装 首先Clojure是JVM" /><meta name="keywords" content="KevinJiang, AI大模型, AI落地, 全栈工程师, Java, Spring Boot" />






<meta name="generator" content="Hugo 0.84.4 with theme even" />


<link rel="canonical" href="http://kevinjiang.info/post/clojure/%E4%BD%BF%E7%94%A8clojure%E5%BC%80%E5%8F%91web%E5%85%A5%E9%97%A8%E7%B3%BB%E5%88%97%E4%B8%80/" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">



<link href="/sass/main.min.78f8f17bab244b9ee62ad16480c9584d5fc2db06ae20681d1ca225cefd80767c.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.css" integrity="sha256-7TyXnr2YU040zfSP+rEcz29ggW4j56/ujTPwjMzyqFY=" crossorigin="anonymous">


<meta property="og:title" content="使用Clojure开发Web入门系列（一）" />
<meta property="og:description" content="对于Clojure语言这里有一些很好的入门教程： Learn X in Y minutes Clojure - Functional Programming for the JVM Clojure koans 零、需要了解的知识 Web http Clojure Leiningen HTML Java 一、安装 首先Clojure是JVM" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://kevinjiang.info/post/clojure/%E4%BD%BF%E7%94%A8clojure%E5%BC%80%E5%8F%91web%E5%85%A5%E9%97%A8%E7%B3%BB%E5%88%97%E4%B8%80/" /><meta property="article:section" content="post" />
<meta property="article:published_time" content="2016-03-07T22:47:33+00:00" />
<meta property="article:modified_time" content="2016-03-07T22:47:33+00:00" />

<meta itemprop="name" content="使用Clojure开发Web入门系列（一）">
<meta itemprop="description" content="对于Clojure语言这里有一些很好的入门教程： Learn X in Y minutes Clojure - Functional Programming for the JVM Clojure koans 零、需要了解的知识 Web http Clojure Leiningen HTML Java 一、安装 首先Clojure是JVM"><meta itemprop="datePublished" content="2016-03-07T22:47:33+00:00" />
<meta itemprop="dateModified" content="2016-03-07T22:47:33+00:00" />
<meta itemprop="wordCount" content="640">
<meta itemprop="keywords" content="Clojure,Web," /><meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="使用Clojure开发Web入门系列（一）"/>
<meta name="twitter:description" content="对于Clojure语言这里有一些很好的入门教程： Learn X in Y minutes Clojure - Functional Programming for the JVM Clojure koans 零、需要了解的知识 Web http Clojure Leiningen HTML Java 一、安装 首先Clojure是JVM"/>

<!--[if lte IE 9]>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/classlist/1.1.20170427/classList.min.js"></script>
<![endif]-->

<!--[if lt IE 9]>
  <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
<![endif]-->

</head>
<body>
  <div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/" class="logo">(Power up)</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>
<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    <a href="/">
        <li class="mobile-menu-item">首页</li>
      </a><a href="/post/">
        <li class="mobile-menu-item">归档</li>
      </a><a href="/tags/">
        <li class="mobile-menu-item">标签</li>
      </a><a href="/categories/">
        <li class="mobile-menu-item">分类</li>
      </a><a href="/resume/">
        <li class="mobile-menu-item">简历</li>
      </a>
  </ul>

  


</nav>

  <div class="container" id="mobile-panel">
    <header id="header" class="header">
        <div class="logo-wrapper">
  <a href="/" class="logo">(Power up)</a>
</div>





<nav class="site-navbar">
  <ul id="menu" class="menu">
    <li class="menu-item">
        <a class="menu-item-link" href="/">首页</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/post/">归档</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/tags/">标签</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/categories/">分类</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/resume/">简历</a>
      </li>
  </ul>
</nav>

    </header>

    <main id="main" class="main">
      <div class="content-wrapper">
        <div id="content" class="content">
          <article class="post">
    
    <header class="post-header">
      <h1 class="post-title">使用Clojure开发Web入门系列（一）</h1>

      <div class="post-meta">
        <span class="post-time"> 2016-03-07 </span>
        
          <span class="more-meta"> 约 640 字 </span>
          <span class="more-meta"> 预计阅读 2 分钟 </span>
        
      </div>
    </header>

    <div class="post-toc" id="post-toc">
  <h2 class="post-toc-title">文章目录</h2>
  <div class="post-toc-content always-active">
    <nav id="TableOfContents">
  <ul>
    <li>
      <ul>
        <li><a href="#零需要了解的知识">零、需要了解的知识</a></li>
        <li><a href="#一安装">一、安装</a></li>
        <li><a href="#二创建项目">二、创建项目</a></li>
      </ul>
    </li>
  </ul>
</nav>
  </div>
</div>
    <div class="post-content">
      <p>对于Clojure语言这里有一些很好的入门教程：</p>
<ol>
<li><a href="https://learnxinyminutes.com/docs/clojure/">Learn X in Y minutes</a></li>
<li><a href="http://java.ociweb.com/mark/clojure/article.html">Clojure - Functional Programming for the JVM</a></li>
<li><a href="https://github.com/functional-koans/clojure-koans">Clojure koans</a></li>
</ol>
<h3 id="零需要了解的知识">零、需要了解的知识</h3>
<ol>
<li>Web</li>
<li><a href="https://www.w3.org/Protocols">http</a></li>
<li><a href="https://clojure.org">Clojure</a></li>
<li><a href="http://leiningen.org">Leiningen</a></li>
<li><a href="https://www.w3.org/html">HTML</a></li>
<li>Java</li>
</ol>
<h3 id="一安装">一、安装</h3>
<p>首先Clojure是JVM上的Lisp方言，所以需要安装Java，可以去官方网站下载安装包，最好下载最新的JDK <a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html">http://www.oracle.com/technetwork/java/javase/downloads/index.html</a>
安装完成之后需要打开命令行窗口看看是否可以执行java命令。</p>
<p>然后安装Leiningen，这个是项目的管理工具，可以管理依赖，编译工程，打包项目等等。可以参照 <a href="http://leiningen.org/#install">http://leiningen.org/#install</a> 介绍的方法。</p>
<!-- raw HTML omitted -->
<h3 id="二创建项目">二、创建项目</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-shell" data-lang="shell">lein new app learnweb
<span class="nb">cd</span> learnweb
</code></pre></td></tr></table>
</div>
</div><p>创建完成后目录结构应该像下面这样：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-text" data-lang="text">├── CHANGELOG.md
├── LICENSE
├── README.md
├── doc
│   └── intro.md
├── project.clj
├── resources
├── src
│   └── learnweb
│       └── core.clj
└── test
    └── learnweb
        └── core_test.clj
</code></pre></td></tr></table>
</div>
</div><p>首先打开<code>project.clj</code>看一眼，这个文件就是定义项目的文件，同样也是使用的<code>clojure</code>的语法</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span><span class="lnt">9
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-clojure" data-lang="clojure"><span class="p">(</span><span class="kd">defproject </span><span class="nv">learnweb</span> <span class="s">&#34;0.1.0-SNAPSHOT&#34;</span>
  <span class="ss">:description</span> <span class="s">&#34;FIXME: write description&#34;</span>
  <span class="ss">:url</span> <span class="s">&#34;http://example.com/FIXME&#34;</span>
  <span class="ss">:license</span> <span class="p">{</span><span class="ss">:name</span> <span class="s">&#34;Eclipse Public License&#34;</span>
            <span class="ss">:url</span> <span class="s">&#34;http://www.eclipse.org/legal/epl-v10.html&#34;</span><span class="p">}</span>
  <span class="ss">:dependencies</span> <span class="p">[[</span><span class="nv">org.clojure/clojure</span> <span class="s">&#34;1.7.0&#34;</span><span class="p">]]</span>
  <span class="ss">:main</span> <span class="o">^</span><span class="ss">:skip-aot</span> <span class="nv">learnweb.core</span>
  <span class="ss">:target-path</span> <span class="s">&#34;target/%s&#34;</span>
  <span class="ss">:profiles</span> <span class="p">{</span><span class="ss">:uberjar</span> <span class="p">{</span><span class="ss">:aot</span> <span class="ss">:all</span><span class="p">}})</span>
</code></pre></td></tr></table>
</div>
</div><p>第一行里定义了项目名字learnweb，版本0.1.0-SNAPSHOT，这两个在打包的时候分体现在文件名上面。
<code>:dependencies</code>包含了项目执行时的所有依赖，后面添加第三方库的时候需要修改这里。
<code>:main</code>指明了程序的入口，是包<code>learnweb.core</code>的<code>-main</code>函数。</p>
<p><code>src</code>目录就是咱们的源代码目录了</p>
<p>现在咱们先来运行一下创建好的项目，使用lein（Leiningen命令）运行：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-clojure" data-lang="clojure"><span class="nv">lein</span> <span class="nv">run</span>
</code></pre></td></tr></table>
</div>
</div><p>你会得到输出<code>Hello, World!</code>。哈哈，入门必经hello world。</p>
<p>完整的代码请checkout到<code>1.1</code>分支。</p>

    </div>

    <div class="post-copyright">
  <p class="copyright-item">
    <span class="item-title">文章作者</span>
    <span class="item-content">Kevin Jiang</span>
  </p>
  <p class="copyright-item">
    <span class="item-title">上次更新</span>
    <span class="item-content">
        2016-03-07
        
    </span>
  </p>
  
  <p class="copyright-item">
    <span class="item-title">许可协议</span>
    <span class="item-content"><a rel="license noopener" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank">CC BY-NC-ND 4.0</a></span>
  </p>
</div>
<div class="post-reward">
  <input type="checkbox" name="reward" id="reward" hidden />
  <label class="reward-button" for="reward">赞赏支持</label>
  <div class="qr-code">
    
    <label class="qr-code-image" for="reward">
        <img class="image" src="/img/wechat_pay_1242x1242.jpg">
        <span>微信打赏</span>
      </label>
    <label class="qr-code-image" for="reward">
        <img class="image" src="/img/alipay_600x600.jpg">
        <span>支付宝打赏</span>
      </label>
  </div>
</div><footer class="post-footer">
      <div class="post-tags">
          <a href="/tags/clojure/">Clojure</a>
          <a href="/tags/web/">Web</a>
          </div>
      <nav class="post-nav">
        <a class="prev" href="/post/clojure/%E4%BD%BF%E7%94%A8clojure%E5%BC%80%E5%8F%91web%E5%85%A5%E9%97%A8%E7%B3%BB%E5%88%97%E4%BA%8C/">
            <i class="iconfont icon-left"></i>
            <span class="prev-text nav-default">使用Clojure开发Web入门系列（二）</span>
            <span class="prev-text nav-mobile">上一篇</span>
          </a>
        <a class="next" href="/post/linux/nagios%E4%BD%BF%E7%94%A8check_nrpe%E8%B0%83%E7%94%A8%E5%AD%90%E5%91%BD%E4%BB%A4/">
            <span class="next-text nav-default">nagios使用check_nrpe调用子命令</span>
            <span class="next-text nav-mobile">下一篇</span>
            <i class="iconfont icon-right"></i>
          </a>
      </nav>
    </footer>
  </article>
        </div>
        

  

  

      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="social-links">
      <a href="mailto:wenlin1988@126.com" class="iconfont icon-email" title="email"></a>
      <a href="https://www.linkedin.com/in/%E6%96%87%E6%9E%97-%E8%92%8B-0a3204126/" class="iconfont icon-linkedin" title="linkedin"></a>
      <a href="https://github.com/kevindragon" class="iconfont icon-github" title="github"></a>
  <a href="http://kevinjiang.info/index.xml" type="application/rss+xml" class="iconfont icon-rss" title="rss"></a>
</div>

<div class="copyright">
  <span class="power-by">
    由 <a class="hexo-link" href="https://gohugo.io">Hugo</a> 强力驱动
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    主题 -
    <a class="theme-link" href="https://github.com/olOwOlo/hugo-theme-even">Even</a>
  </span>

  

  <span class="copyright-year">
    &copy;
    2015 -
    2023<span class="heart"><i class="iconfont icon-heart"></i></span><span>Kevin Jiang</span>
    <a href="https://beian.miit.gov.cn/" target="_blank">湘ICP备2022022745号</a>
  </span>
</div>

    </footer>

    <div class="back-to-top" id="back-to-top">
      <i class="iconfont icon-up"></i>
    </div>
  </div>
  
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/slideout@1.0.1/dist/slideout.min.js" integrity="sha256-t+zJ/g8/KXIJMjSVQdnibt4dlaDxc9zXr/9oNPeWqdg=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.js" integrity="sha256-XVLffZaxoWfGUEbdzuLi7pwaUJv1cecsQJQqGLe7axY=" crossorigin="anonymous"></script>



<script type="text/javascript" src="/js/main.min.c99b103c33d1539acf3025e1913697534542c4a5aa5af0ccc20475ed2863603b.js"></script>
  <script type="text/javascript">
    window.MathJax = {
      tex: {
        inlineMath: [['$','$'], ['\\(','\\)']],
        tags: 'ams',
        }
    };
  </script>
  <script type="text/javascript" async src="/lib/mathjax/es5/tex-mml-chtml.js"></script>

<script id="baidu_analytics">
  var _hmt = _hmt || [];
  (function() {
    if (window.location.hostname === 'localhost') return;
    var hm = document.createElement("script"); hm.async = true;
    hm.src = "https://hm.baidu.com/hm.js?b73ff6d4afc4af9e582d8a5dc068bab9";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
  })();
</script>






</body>
</html>
